﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Text;

using FCNS.KeepMoneyLibrary.Util;

namespace FCNS.KeepMoneyLibrary.Data
{
    public class InterestField
    {
        public enum InterestMode
        {
            日息=0,
            周息,
            月息,
            年息
        }
        //static Dictionary<string, int> dic = new Dictionary<string, int>();
        //public static Dictionary<string, int> InterestMode
        //{
        //    get
        //    {
        //        if (dic.Count == 0)
        //        {
        //            //不能更改此次序
        //            dic[TranslateUtil.日息] = 0;
        //            dic[TranslateUtil.周息] = 1;
        //            dic[TranslateUtil.月息] = 2;
        //            dic[TranslateUtil.年息] = 3;
        //        }

        //        return dic;
        //    }
        //}


        public void Remove()
        {
            KMData.DataTableInterest.Rows.Remove(dRow);
            fields.Remove(this);
        }

        bool add = false;
        public void AddRowToDataTable()
        {
            if (!add)
                return;

            KMData.DataTableInterest.Rows.Add(dRow);
            fields.Add(this);
            add = false;
        }

        static List<InterestField> fields = new List<InterestField>();
        public static List<InterestField> GetInterestField
        {
            get
            {
                if (fields.Count == 0)
                    foreach (DataRow row in KMData.DataTableInterest.Rows)
                        fields.Add(new InterestField(row));

                return fields;
            }
        }

        DataRow dRow = null;
        public InterestField(DataRow row)
        {
            if (row == null)
            {
                dRow = KMData.DataTableInterest.NewRow();
                add = true;
            }
            else
                dRow = row;
        }

        public int Id
        {
            get { return (int)dRow["Id"]; }
            set { dRow["Id"] = value; }
        }

        public int Mode
        {
            get { return (int)dRow["Mode"]; }
            set { dRow["Mode"] = value; }
        }

        public decimal Value
        {
            get { return (decimal)dRow["Value"]; }
            set { dRow["Value"] = value; }
        }

        public string columnName
        {
            get { return (string)dRow["Name"]; }
            set { dRow["Name"] = value; }
        }

        public string columnMode
        {
            get
            {
                return Enum.GetName(typeof(InterestMode), Mode);
            }
        }

        public string columnValue
        {
            get
            {
                if (Value > 1)
                    return Value.ToString();
                else
                    return Value.ToString();
                   // return Value.ToString("p" + Program.AppConfig.Money.Precision.ToString());
            }
        }

    }
}
